﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Web_Oto.Bases;
using Web_Oto.Data;
using Web_Oto.Data.Dto;

namespace Web_Oto.Business
{
    public class ProductBus : busObject
    {
        #region Constructor
        public ProductBus() : base()
        {
            m_objDAL = new ProductDal(base.connectionstring, base.connectiontype);
        }

        public ProductBus(string connectionString) : base(connectionString)
        {
            m_objDAL = new ProductDal(base.connectionstring, base.connectiontype);
        }

        public ProductBus(string connectionString, string connectionType)
            : base(connectionString, connectionType)
        {
            m_objDAL = new ProductDal(base.connectionstring, base.connectiontype);
        }

        private ProductDal m_objDAL;

        #endregion

        #region methods
        public IList<ProductDto> GetAllProduct(int? currentpage, int? itemsperpage, out int totalRecord)
        {
            return m_objDAL.GetAllProduct(currentpage,itemsperpage, out totalRecord);
        }

        public IList<ProductDto> GetProducts(int? categoryId, int? parentId, int? currentpage, int? itemsperpage, out int totalRecord)
        {
            return m_objDAL.GetProducts(categoryId, parentId, currentpage, itemsperpage, out totalRecord);
        }

        public IList<ProductDto> GetTopProducts(int showItems)
        {
            return m_objDAL.GetTopProducts(showItems);
        }

        public IList<ProductDto> GetProductForSlide(int showItems, bool? isHomepage, bool? isNews, bool? isService, bool? isPayment)
        {
            return m_objDAL.GetProductForSlide(showItems, isHomepage, isNews, isService, isPayment);
        }

        public ProductDto GetProductById(int productId)
        {
            return m_objDAL.GetProductById(productId);
        }

        public int? GetCategoryByName(string name)
        {
            return m_objDAL.GetCategoryByName(name);
        }

        public IList<ProductDto> GetProductDtos(string name = "", int categoryId = 0, int id = 0)
        {
            return m_objDAL.GetProductDtos(name, categoryId, id);
        }

        public int Insert(ProductDto productDto)
        {
            return m_objDAL.Insert(productDto);
        }

        public int Update(ProductDto productDto, bool isUpdateRelation = true)
        {
            return m_objDAL.Update(productDto, isUpdateRelation);
        }

        public int Delete(int id)
        {
            return m_objDAL.Delete(id);
        }

        public List<ProductDto> GetRelativeProductDto(int productId)
        {
            return m_objDAL.GetRelativeProductDto(productId);
        }

        public List<ProductDto> GetRelativeProductDto(int productId, int? showItems)
        {
            return m_objDAL.GetRelativeProductDto(productId, showItems);
        }

        public IList<ProductDto> SearchProduct(string keyword, int? currentPage, int? itemPerPage, out int totalRecord)
        {
            return m_objDAL.SearchProduct(keyword, currentPage, itemPerPage, out totalRecord);
        }

        public string GetFilePathById(int productId)
        {
            return m_objDAL.GetFilePathById(productId);
        }

        #endregion
    }
}
